package test.org.macpro.alone.server.common;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.macpro.alone.prisist.domain.AloneUser;
import org.macpro.alone.server.common.database.DataComplexQueryManagerInter;
import org.macpro.alone.server.domain.PageDomain;
import org.macpro.alone.server.domain.SqlDomain;
import org.macpro.alone.server.domain.SqlDomain.LimitDomain;
import org.macpro.alone.server.framework.base.AloneBeanFactory;
import org.macpro.alone.server.util.PageDomainHandle;

public class ComplexQueryTest2 {
	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		DataComplexQueryManagerInter dqm = (DataComplexQueryManagerInter) AloneBeanFactory
				.getBean("COMPLET_QUERY_ALONE_COMMON");
		{
			PageDomain pd = new PageDomain(1);
			List<LimitDomain> limitList = new ArrayList<LimitDomain>();
			SqlDomain sqldomain = new SqlDomain("alone_user a left join alone_organization_user b on a.id=b.userid", "a.name", "asc",
					limitList);
			pd = dqm.runComplexQuery(
							pd, "a.name,a.password,b.CTIME",sqldomain );
			List<Map<String, String>> list = PageDomainHandle
					.getStringArrayForPageDomain(pd);
			for (Iterator iterator = list.iterator(); iterator.hasNext();) {
				Map<String, String> name = (Map<String, String>) iterator
						.next();
				System.out.print(name.get("A.PASSWORD"));
				System.out.print(name.get("A.NAME"));
				System.out.println(name.get("B.CTIME"));
			}
		}
		{
			// ---------------------------------------------
			PageDomain page = new PageDomain(0);
			List<LimitDomain> limitList = new ArrayList<LimitDomain>();
			// limitList.add(new LimitDomain("","",""));
			SqlDomain sqldomain = new SqlDomain("alone_user", "id", "asc",
					limitList);
			page = dqm.runComplexQuery(page, new AloneUser(), sqldomain);
			List<Map<String, String>> list2 = PageDomainHandle
					.getStringArrayForPageDomain(page);
			for (Iterator iterator = list2.iterator(); iterator.hasNext();) {
				Map<String, String> name = (Map<String, String>) iterator
						.next();
				System.out.println(name.get("NAME"));
			}
		}
	}
}
